package com.netease.pris.activity.view;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.ListAdapter;
import com.netease.g.b;
import com.netease.pris.app.PrisApp;

public class TouchInterceptor extends NeteaseListView
{
  private static final String b = "TouchInterceptor";
  private static final int r = 0;
  private static final int s = 1;
  private static final int t = 2;
  private static final int u = 4;
  private int A;
  private int B;
  private Drawable C;
  private boolean D = true;
  private int E = -1;
  private au F;
  private View G;
  private boolean H;
  private Runnable I;
  private Handler J = new bj(this);
  private boolean a = false;
  private ImageView c;
  private WindowManager d;
  private WindowManager.LayoutParams e;
  private int f;
  private int g;
  private int h;
  private int i;
  private int j;
  private int k;
  private af l;
  private bw m;
  private k n;
  private int o;
  private int p;
  private int q;
  private int v = -1;
  private Rect w = new Rect();
  private Bitmap x;
  private final int y;
  private int z;

  public TouchInterceptor(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.v = paramContext.getSharedPreferences("Music", 3).getInt("deletemode", -1);
    this.y = ViewConfiguration.get(paramContext).getScaledTouchSlop();
    Resources localResources = getResources();
    this.z = localResources.getDimensionPixelSize(2131296256);
    this.B = (this.z / 2);
    this.A = localResources.getDimensionPixelSize(2131296257);
  }

  private int a(int paramInt)
  {
    int i1 = 0;
    int i2 = paramInt - this.i - this.B;
    int i3 = pointToPosition(0, i2);
    if (i3 >= 0)
    {
      if (i3 <= this.g)
        i3++;
      if (this.a)
        Log.i("TouchInterceptor", "directly return, pos ret: " + i3);
    }
    while (true)
    {
      return i3;
      if (i2 >= getPaddingTop())
        break;
      if (this.a)
        Log.i("TouchInterceptor", "adjustedy < getPaddingTop(), padding-top: " + getPaddingTop());
      i3 = 0 + getFirstVisiblePosition();
    }
    int i4 = this.B;
    if (this.a)
      Log.w("TouchInterceptor", "original-adjustedy: " + i2 + ", height-half: " + this.B + ", divider-height: " + getDividerHeight() + ", padding-bottom: " + getPaddingBottom() + ", padding-top: " + getPaddingTop() + ", step: " + i4);
    int i5 = 0;
    label228: i2 += i4;
    int i7;
    if (i2 >= this.q)
    {
      if (this.a)
        Log.i("TouchInterceptor", "adjustedy >= mHeight");
      i7 = -1 + getChildCount();
      if (i7 >= 0)
        break label378;
    }
    while (true)
    {
      if (i1 <= this.g)
        i1++;
      i3 = i1;
      break;
      if (i2 <= getPaddingTop())
      {
        if (!this.a)
          continue;
        Log.i("TouchInterceptor", "adjustedy <= getPaddingTop()");
        continue;
      }
      int i6 = pointToPosition(0, i2);
      if (this.a)
        Log.i("TouchInterceptor", "pos: " + i6 + ", time: " + i5);
      i5++;
      if (i6 < 0)
        break label228;
      i1 = i6;
      continue;
      label378: i1 = i7;
    }
  }

  private int a(int paramInt1, int paramInt2)
  {
    int i2;
    if (paramInt2 < 0)
    {
      int i3 = a(paramInt1, paramInt2 + this.z);
      if (i3 > 0)
        i2 = i3 - 1;
    }
    while (true)
    {
      return i2;
      Rect localRect = this.w;
      for (int i1 = -1 + getChildCount(); ; i1--)
      {
        if (i1 < 0)
          break label87;
        getChildAt(i1).getHitRect(localRect);
        if (!localRect.contains(paramInt1, paramInt2))
          continue;
        i2 = i1 + getFirstVisiblePosition();
        break;
      }
      label87: i2 = -1;
    }
  }

  private int a(ViewGroup paramViewGroup)
  {
    int i1 = -1;
    if (paramViewGroup == null);
    while (true)
    {
      return i1;
      View localView = paramViewGroup.findViewById(2131558486);
      if (localView == null)
        continue;
      i1 = localView.getLeft();
    }
  }

  private void a()
  {
    for (int i1 = -1 + getChildCount(); i1 >= 0; i1--)
    {
      View localView = getChildAt(i1);
      if (localView == null)
        continue;
      ViewGroup.LayoutParams localLayoutParams = localView.getLayoutParams();
      localLayoutParams.height = this.z;
      localView.setLayoutParams(localLayoutParams);
      localView.setVisibility(0);
    }
  }

  private void a(Bitmap paramBitmap, int paramInt1, int paramInt2)
  {
    i();
    this.e = new WindowManager.LayoutParams();
    this.e.gravity = 51;
    this.e.x = (paramInt1 - this.h + this.j);
    this.e.y = (paramInt2 - this.i + this.k);
    this.e.height = -2;
    this.e.width = -2;
    this.e.flags = 920;
    this.e.format = -3;
    this.e.windowAnimations = 0;
    Context localContext = getContext();
    ImageView localImageView = new ImageView(localContext);
    localImageView.setPadding(0, 0, 0, 0);
    localImageView.setImageBitmap(paramBitmap);
    localImageView.setBackgroundDrawable(com.netease.framework.k.a(getContext()).b(2130837602));
    localImageView.setAlpha(220);
    this.x = paramBitmap;
    this.d = ((WindowManager)localContext.getSystemService("window"));
    this.d.addView(localImageView, this.e);
    this.c = localImageView;
  }

  private void b()
  {
    int i1 = this.f - getFirstVisiblePosition();
    if (this.f > this.g)
      i1++;
    int i2 = getHeaderViewsCount();
    View localView1 = getChildAt(this.g - getFirstVisiblePosition());
    int i3 = 0;
    View localView2 = getChildAt(i3);
    if (localView2 == null)
      return;
    int i4 = this.z;
    int i5;
    int i6;
    if ((this.f < i2) && (i3 == i2))
      if (localView2.equals(localView1))
      {
        i5 = i4;
        i6 = 4;
      }
    while (true)
    {
      ViewGroup.LayoutParams localLayoutParams = localView2.getLayoutParams();
      localLayoutParams.height = i5;
      localView2.setLayoutParams(localLayoutParams);
      localView2.setVisibility(i6);
      i3++;
      break;
      i5 = this.A;
      i6 = 0;
      continue;
      if (localView2.equals(localView1))
      {
        if ((this.f == this.g) || (getPositionForView(localView2) == -1 + getCount()))
        {
          i5 = i4;
          i6 = 4;
          continue;
        }
        i5 = 1;
        i6 = 0;
        continue;
      }
      if ((i3 == i1) && (this.f >= i2) && (this.f <= -1 + getCount()))
      {
        i5 = this.A;
        i6 = 0;
        continue;
      }
      i5 = i4;
      i6 = 0;
    }
  }

  private void b(int paramInt)
  {
    this.o = (this.q / 3);
    this.p = (2 * this.q / 3);
  }

  private void b(int paramInt1, int paramInt2)
  {
    if (this.v == 1)
    {
      float f1 = 1.0F;
      int i2 = this.c.getWidth();
      if (paramInt1 > i2 / 2)
        f1 = (i2 - paramInt1) / (i2 / 2);
      this.e.alpha = f1;
    }
    int i1;
    if ((this.v == 0) || (this.v == 2))
    {
      this.e.x = (paramInt1 - this.h + this.j);
      this.e.y = (paramInt2 - this.i + this.k);
      this.d.updateViewLayout(this.c, this.e);
      if (this.C != null)
      {
        i1 = this.c.getWidth();
        if (paramInt2 <= 3 * getHeight() / 4)
          break label166;
        this.C.setLevel(2);
      }
    }
    while (true)
    {
      return;
      this.e.x = 0;
      break;
      label166: if ((i1 > 0) && (paramInt1 > i1 / 4))
      {
        this.C.setLevel(1);
        continue;
      }
      this.C.setLevel(0);
    }
  }

  private void c()
  {
    if (this.a)
      Log.i("TouchInterceptor", "scroll(), mDragY: " + this.E);
    if (this.E < 0);
    int i1;
    do
    {
      return;
      i1 = a(this.E);
    }
    while (i1 < 0);
    if (i1 != this.f)
    {
      if (this.l != null)
        this.l.a(this.f, i1);
      this.f = i1;
    }
    int i5;
    label154: int i2;
    if (this.E >= this.p)
    {
      if (this.a)
        Log.i("TouchInterceptor", "mDragY >= mLowerBound");
      if (getLastVisiblePosition() <= -1 + getCount())
        if (this.E > (this.q + this.p) / 2)
        {
          i5 = 32;
          i2 = i5;
        }
    }
    while (true)
    {
      int i4;
      if (i2 != 0)
      {
        int i3 = pointToPosition(0, this.q / 2);
        if (i3 < 0)
          i3 = h();
        View localView = getChildAt(i3 - getFirstVisiblePosition());
        if (localView == null)
          break;
        setSelectionFromTop(i3, localView.getTop() - i2);
        break;
        i5 = 16;
        break label154;
        if (e())
        {
          if (this.a)
            Log.i("TouchInterceptor", "at bottom");
          i2 = 0;
          continue;
          if (this.E <= this.o)
          {
            if (this.a)
              Log.i("TouchInterceptor", "mDragY <= mUpperBound");
            if (this.E < this.o / 2);
            for (i4 = -32; ; i4 = -16)
            {
              if (!d())
                break label373;
              if (this.a)
                Log.i("TouchInterceptor", "at top");
              i2 = 0;
              break;
            }
          }
          if (this.a)
            Log.w("TouchInterceptor", "not in move range!");
        }
        i2 = 0;
        continue;
      }
      if (!this.a)
        break;
      Log.e("TouchInterceptor", "deltaDistance == 0");
      break;
      label373: i2 = i4;
    }
  }

  private boolean d()
  {
    int i1 = 0;
    if ((getFirstVisiblePosition() == 0) && (getChildAt(0).getTop() >= getPaddingTop()))
      i1 = 1;
    return i1;
  }

  private boolean e()
  {
    int i1 = getLastVisiblePosition();
    if ((getChildAt(i1) != null) && (getChildAt(i1).getBottom() > this.q - getPaddingBottom()));
    for (int i2 = 1; ; i2 = 0)
      return i2;
  }

  private void f()
  {
    if (this.a)
      Log.i("TouchInterceptor", "stop thread");
    this.E = -1;
    if (this.F != null)
    {
      this.F.a();
      this.F.interrupt();
      this.F = null;
    }
  }

  private void g()
  {
    if (this.a)
      Log.i("TouchInterceptor", "start thread");
    if (this.F == null)
    {
      this.F = new au(this, null);
      this.F.start();
    }
  }

  private int h()
  {
    int i1 = this.q / 2 + getDividerHeight() + this.z;
    int i2 = this.z / 10;
    int i3;
    do
    {
      i3 = pointToPosition(0, i1);
      i1 += i2;
      if (i1 < this.q)
        continue;
      i1 -= i2 + this.z;
    }
    while (i3 < 0);
    return i3;
  }

  private void i()
  {
    boolean bool1 = true;
    if (this.a)
      Log.i("TouchInterceptor", "stopDragging()");
    boolean bool2;
    boolean bool3;
    label73: StringBuilder localStringBuilder3;
    if (this.a)
    {
      StringBuilder localStringBuilder1 = new StringBuilder().append("mDragView == null: ");
      if (this.c != null)
        break label197;
      bool2 = bool1;
      StringBuilder localStringBuilder2 = localStringBuilder1.append(bool2).append("mDragBitmap == null: ");
      if (this.x != null)
        break label203;
      bool3 = bool1;
      localStringBuilder3 = localStringBuilder2.append(bool3).append("mTrashcan == null: ");
      if (this.C != null)
        break label209;
    }
    while (true)
    {
      Log.i("TouchInterceptor", bool1);
      if (this.c != null)
      {
        this.c.setVisibility(8);
        ((WindowManager)getContext().getSystemService("window")).removeView(this.c);
        this.c.setImageDrawable(null);
        this.c = null;
      }
      if (this.x != null)
      {
        this.x.recycle();
        this.x = null;
      }
      if (this.C != null)
        this.C.setLevel(0);
      return;
      label197: bool2 = false;
      break;
      label203: bool3 = false;
      break label73;
      label209: bool1 = false;
    }
  }

  private void j()
  {
    k();
    this.H = true;
  }

  private void k()
  {
    int i1 = this.f - getFirstVisiblePosition();
    if (this.f > this.g)
      i1++;
    View localView = getChildAt(i1);
    if (localView == null);
    while (true)
    {
      return;
      this.G = localView;
      ViewGroup.LayoutParams localLayoutParams = this.G.getLayoutParams();
      localLayoutParams.height = this.A;
      this.G.setLayoutParams(localLayoutParams);
    }
  }

  private void l()
  {
    if (this.G != null)
    {
      ViewGroup.LayoutParams localLayoutParams = this.G.getLayoutParams();
      localLayoutParams.height = this.z;
      this.G.setLayoutParams(localLayoutParams);
      this.G = null;
    }
  }

  public void a(Drawable paramDrawable)
  {
    this.C = paramDrawable;
    this.v = 2;
  }

  public void a(af paramaf)
  {
    this.l = paramaf;
  }

  public void a(bw parambw)
  {
    this.m = parambw;
  }

  public void a(k paramk)
  {
    this.n = paramk;
  }

  public void a(boolean paramBoolean)
  {
    this.D = paramBoolean;
  }

  protected void dispatchDraw(Canvas paramCanvas)
  {
    super.dispatchDraw(paramCanvas);
    if (getContext().getPackageName().equals(PrisApp.a().A()));
    for (int i1 = 2130837604; ; i1 = 2130837605)
    {
      Bitmap localBitmap1 = BitmapFactory.decodeResource(getResources(), i1);
      Bitmap localBitmap2 = Bitmap.createScaledBitmap(localBitmap1, paramCanvas.getWidth(), localBitmap1.getHeight(), false);
      localBitmap1.recycle();
      paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, null);
      return;
    }
  }

  public int getSolidColor()
  {
    return com.netease.framework.k.a(getContext()).c(2131230998);
  }

  public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
  {
    boolean bool;
    if (!this.D)
    {
      b.e("TouchInterceptor", "set to could not drag and re-order, ignore intercept touch gesture.");
      bool = super.onInterceptTouchEvent(paramMotionEvent);
      return bool;
    }
    b.e("TouchInterceptor", "onInterceptTouchEvent(), action: " + paramMotionEvent.getAction());
    if ((this.l != null) || (this.m != null))
      switch (paramMotionEvent.getAction())
      {
      default:
      case 0:
      }
    while (true)
    {
      bool = super.onInterceptTouchEvent(paramMotionEvent);
      break;
      int i1 = (int)paramMotionEvent.getX();
      int i2 = (int)paramMotionEvent.getY();
      int i3 = pointToPosition(i1, i2);
      if ((i3 == -1) || (i3 == -1 + getAdapter().getCount()))
        continue;
      ViewGroup localViewGroup = (ViewGroup)getChildAt(i3 - getFirstVisiblePosition());
      this.h = (i1 - localViewGroup.getLeft());
      this.i = (i2 - localViewGroup.getTop());
      this.j = ((int)paramMotionEvent.getRawX() - i1);
      this.k = ((int)paramMotionEvent.getRawY() - i2);
      int i4 = a(localViewGroup);
      if ((i4 > 0) && (i1 > i4))
      {
        localViewGroup.setDrawingCacheEnabled(true);
        a(Bitmap.createBitmap(localViewGroup.getDrawingCache()), i1, i2);
        this.f = i3;
        this.g = this.f;
        this.q = getHeight();
        b(i2);
        bool = false;
        break;
      }
      b.f("TouchInterceptor", "drag down point is not in the process touch domain, ignore");
      i();
      continue;
      b.d("TouchInterceptor", "mDragListener is null and mDropListener is null!");
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    boolean bool1 = true;
    if (!this.D)
    {
      b.e("TouchInterceptor", "set to could not drag and re-order, ignore touch gesture.");
      bool1 = super.onTouchEvent(paramMotionEvent);
    }
    while (true)
    {
      return bool1;
      b.e("TouchInterceptor", "onTouchEvent(), action: " + paramMotionEvent.getAction());
      int i1;
      int i2;
      int i3;
      if (((this.l != null) || (this.m != null)) && (this.c != null))
      {
        i1 = (int)paramMotionEvent.getX();
        i2 = (int)paramMotionEvent.getY();
        i3 = paramMotionEvent.getAction();
      }
      switch (i3)
      {
      default:
        break;
      case 0:
        this.E = i2;
        break;
      case 1:
      case 3:
        if (this.a)
          Log.i("TouchInterceptor", "action: " + i3);
        f();
        i();
        StringBuilder localStringBuilder;
        if (this.a)
        {
          localStringBuilder = new StringBuilder().append("mDropListener == null: ");
          if (this.m != null)
            break label369;
        }
        for (boolean bool2 = bool1; ; bool2 = false)
        {
          Log.i("TouchInterceptor", bool2 + ", mDragPos: " + this.f + ", getCount(): " + getCount() + ", mSrcDragPos: " + this.g + ", getAdapter().getCount(): " + getAdapter().getCount());
          if ((this.m == null) || (this.f < 0) || (this.f >= getCount()) || (this.g >= -1 + getAdapter().getCount()))
            break label375;
          this.m.a(this.g, this.f);
          int i4 = (int)paramMotionEvent.getY() - this.i;
          setSelectionFromTop(this.f, i4);
          break;
        }
        if (this.g != -1 + getAdapter().getCount())
          continue;
        setAdapter(getAdapter());
        break;
      case 2:
        label369: label375: b(i1, i2);
        this.E = i2;
        g();
        continue;
        bool1 = super.onTouchEvent(paramMotionEvent);
      }
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.view.TouchInterceptor
 * JD-Core Version:    0.6.0
 */